package com.data.app.dao.pg;

import com.data.app.commons.constant.CommonConstant;
import com.data.app.pojo.pg.CityHouseEntity;
import com.data.app.pojo.pg.CountryDlHouseEntity;
import com.data.app.pojo.pg.CountryNonHouseEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDate;
import java.util.List;

public interface CountryDlHouseBaseDao extends JpaRepository<CountryDlHouseEntity, String> {

    // @Query(nativeQuery = true, value = "select * from "+ CommonConstant.TABLE_NAME_COUNTRY_DL_HOUSE)
    // List<CountryDlHouseEntity> findDlHouseAll();//10.7.208.200
    @Query(nativeQuery = true, value = "select * from "+ CommonConstant.TABLE_NAME_COUNTRY_DL_HOUSE +
            " where district =:city")
    List<CountryDlHouseEntity> findDlHouseAll(String city);//207 '371600','371700'

    /**
     * 查询该时间段内的新增数据
     * @param startDate
     * @param endDate
     * @return
     */
    @Query(nativeQuery = true, value = "select * from "+ CommonConstant.TABLE_NAME_COUNTRY_DL_HOUSE +" WHERE CAST(create_time AS  DATE) BETWEEN DATE(:startDate) and DATE(:endDate)")
    List<CountryDlHouseEntity> findAddByDate(@Param(value = "startDate") LocalDate startDate, @Param(value = "endDate") LocalDate endDate);

    /**
     * 查询时间段内修改数据
     * @param startDate
     * @param endDate
     * @return
     */
    @Query(nativeQuery = true, value = "select * from "+CommonConstant.TABLE_NAME_COUNTRY_DL_HOUSE+" WHERE create_time!=update_time and  CAST(update_time AS  DATE) BETWEEN DATE(:startDate) and DATE(:endDate)")
    List<CountryDlHouseEntity> findUpdateByDate(@Param(value = "startDate") LocalDate startDate,@Param(value = "endDate") LocalDate endDate);

}
